//
//  HypnosisViewController.m
//  Hypnosister
//
//  Created by Xia Yong on 12-12-27.
//  Copyright (c) 2012年 Xia Yong. All rights reserved.
//

#import "HypnosisViewController.h"

@interface HypnosisViewController () <UIScrollViewDelegate>

// 改方法要求返回UIScrollView对象需要缩放的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;

@end

@implementation HypnosisViewController

@synthesize hypnosisView = _hypnosisView;
@synthesize scrollScreen = _scrollScreen;

- (void)viewDidLoad
{
    [super viewDidLoad];    
    // 获取窗口的大小,坐标
    CGRect wholeWindow = [self.view bounds];
    
    // 将UIScrollView视图设置为窗口的2倍
    CGRect reallyBigRect;
    reallyBigRect.origin = CGPointZero;
    reallyBigRect.size.width = wholeWindow.size.width * 2;
    reallyBigRect.size.height = wholeWindow.size.height * 2;
    [self.scrollScreen setContentSize:reallyBigRect.size];
    
    // 启用缩放功能
    [self.scrollScreen setMinimumZoomScale:0.5];
    [self.scrollScreen setMaximumZoomScale:5];
    [self.scrollScreen setDelegate:self];
    
    // 使视图在UIScrollView对象里居中
    CGPoint offset;
    offset.x = wholeWindow.size.width / 2;
    offset.y = wholeWindow.size.height / 2;
    [self.scrollScreen setContentOffset:offset];
    
    // 创建HypnosisView实例，大小和窗口颜色
    self.hypnosisView = [[HypnosisView alloc] initWithFrame:reallyBigRect];
    
    // 将该视图的背景色设置为全透明白色:clear
    [self.hypnosisView setBackgroundColor:[UIColor clearColor]];
    
    // 将该视图加入视图层次结构
    [self.scrollScreen addSubview:self.hypnosisView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.hypnosisView;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
